<?php
/**
 * Created by PhpStorm.
 * User: linlin
 * Date: 2017/3/9
 * Time: 14:35
 */
namespace app\filters;

use Yii;
use yii\base\ActionFilter;
use yii\web\NotFoundHttpException;

class Json extends ActionFilter
{
    public function beforeAction($action)
    {
        $response = Yii::$app->response;
        $response->format = \yii\web\Response::FORMAT_JSON;
        return parent::beforeAction($action);
    }
    public static function success($data = [],$msg = '成功'){
        $returnData = [
            'status'=>'1',
            'msg'=>$msg,
        ];
        if(!empty($data)){
            $returnData['data'] = $data;
        }
        return $returnData;
    }
    public static function error($msg = '失败',$status = '0'){
        return [
            'status'=>'0',
            'msg'=>$msg,
        ];
    }
}